package io.renren.modules.sys.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.sys.dao.TalentsDao;
import io.renren.modules.sys.entity.TalentsEntity;
import io.renren.modules.sys.service.TalentsService;


@Service("talentsService")
public class TalentsServiceImpl extends ServiceImpl<TalentsDao, TalentsEntity> implements TalentsService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
    	DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        
        Date startDate=null;
        if(null!=params.get("startDate")&&!StringUtils.isEmpty(params.get("startDate").toString())) {
        	try {
        		startDate=format.parse(params.get("startDate").toString());
			} catch (ParseException e) {
				e.printStackTrace();
			} 
        }
    	Date endDate=null;
        if(null!=params.get("endDate")&&!StringUtils.isEmpty(params.get("endDate").toString())) {
        	try {
        		endDate=format.parse(params.get("endDate").toString());
			} catch (ParseException e) {
				e.printStackTrace();
			} 
        }
    	Integer userId=null;
    	if(null!=params.get("userId")&&!StringUtils.isEmpty(params.get("userId").toString())) {
    		userId=Integer.valueOf(params.get("userId").toString());
    	}
    	
		String name = (String)params.get("name");
		String phone = (String)params.get("phone");
		String jobExperience = (String)params.get("jobExperience");
		
		String contractNum = (String)params.get("contractNum");

		String use = (String)params.get("use");

		String zhuce = (String)params.get("zhuce");

		Integer status=null;
    	if(null!=params.get("status")&&!StringUtils.isEmpty(params.get("status").toString())) {
    		status=Integer.valueOf(params.get("status").toString());
    	}
    	
		Integer com=null;
    	if(null!=params.get("com")&&!StringUtils.isEmpty(params.get("com").toString())) {
    		com=Integer.valueOf(params.get("com").toString());
    	}

		String education = (String)params.get("education");

		
		String province = (String)params.get("province");
		String city = (String)params.get("city");

		String certificateProvince = (String)params.get("certificateProvince");
		String certificateCity = (String)params.get("certificateCity");

		String job2 = (String)params.get("job2");
		String job = (String)params.get("job");

		
        Page<TalentsEntity> page = this.selectPage(
                new Query<TalentsEntity>(params).getPage(),
                new EntityWrapper<TalentsEntity>()
                .addFilterIfNeed(null!=userId, "user_id={0}", userId)
                .ge(null!=startDate, "certificate_date", startDate)
                .le(null!=endDate, "certificate_date", endDate)
                .like(!StringUtils.isEmpty(name), "name", name)
                .addFilterIfNeed(!StringUtils.isEmpty(phone), "phone={0}", phone)
                .addFilterIfNeed(!StringUtils.isEmpty(jobExperience), "job_experience={0}", jobExperience)
                .addFilterIfNeed(!StringUtils.isEmpty(contractNum), "contract_num={0}", contractNum)
                .addFilterIfNeed(!StringUtils.isEmpty(use), "use={0}", use)
                .addFilterIfNeed(!StringUtils.isEmpty(zhuce), "zhuce={0}", zhuce)
                .addFilterIfNeed(null!=status, "status={0}", status)
                .addFilterIfNeed(!StringUtils.isEmpty(education), "education={0}", education)
                .addFilterIfNeed(null!=com, "com={0}", com)
                .addFilterIfNeed(!StringUtils.isEmpty(province), "province={0}", province)
                .addFilterIfNeed(!StringUtils.isEmpty(city), "city={0}", city)
                .addFilterIfNeed(!StringUtils.isEmpty(certificateProvince), "certificate_province={0}", certificateProvince)
                .addFilterIfNeed(!StringUtils.isEmpty(certificateCity), "certificate_city={0}", certificateCity)
                .addFilterIfNeed(!StringUtils.isEmpty(job2), "job2={0}", job2)
                .addFilterIfNeed(!StringUtils.isEmpty(job), "job={0}", job)
                .addFilter("is_del={0}", 0)
                .orderBy("upd_time", false)
        		);
        return new PageUtils(page);
    }
    
    @Override
    public PageUtils queryPage2(Map<String, Object> params) {
    	DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        
        Date startDate=null;
        if(null!=params.get("startDate")&&!StringUtils.isEmpty(params.get("startDate").toString())) {
        	try {
        		startDate=format.parse(params.get("startDate").toString());
			} catch (ParseException e) {
				e.printStackTrace();
			} 
        }
    	Date endDate=null;
        if(null!=params.get("endDate")&&!StringUtils.isEmpty(params.get("endDate").toString())) {
        	try {
        		endDate=format.parse(params.get("endDate").toString());
			} catch (ParseException e) {
				e.printStackTrace();
			} 
        }
    	Integer userId=null;
    	if(null!=params.get("userId")&&!StringUtils.isEmpty(params.get("userId").toString())) {
    		userId=Integer.valueOf(params.get("userId").toString());
    	}
    	
		String name = (String)params.get("name");
		String phone = (String)params.get("phone");
		String jobExperience = (String)params.get("jobExperience");
		
		String contractNum = (String)params.get("contractNum");

		String use = (String)params.get("use");

		String zhuce = (String)params.get("zhuce");

		Integer status=null;
    	if(null!=params.get("status")&&!StringUtils.isEmpty(params.get("status").toString())) {
    		status=Integer.valueOf(params.get("status").toString());
    	}
    	
		Integer com=null;
    	if(null!=params.get("com")&&!StringUtils.isEmpty(params.get("com").toString())) {
    		status=Integer.valueOf(params.get("com").toString());
    	}

		String education = (String)params.get("education");

		
		String province = (String)params.get("province");
		String city = (String)params.get("city");

		String certificateProvince = (String)params.get("certificateProvince");
		String certificateCity = (String)params.get("certificateCity");

		String job2 = (String)params.get("job2");
		String job = (String)params.get("job");

		
        Page<TalentsEntity> page = this.selectPage(
                new Query<TalentsEntity>(params).getPage(),
                new EntityWrapper<TalentsEntity>()
                .addFilterIfNeed(null!=userId, "user_id={0}", userId)
                .ge(null!=startDate, "certificate_date", startDate)
                .le(null!=endDate, "certificate_date", endDate)
                .like(!StringUtils.isEmpty(name), "name", name)
                .addFilterIfNeed(!StringUtils.isEmpty(phone), "phone={0}", phone)
                .addFilterIfNeed(!StringUtils.isEmpty(jobExperience), "job_experience={0}", jobExperience)
                .addFilterIfNeed(!StringUtils.isEmpty(contractNum), "contract_num={0}", contractNum)
                .addFilterIfNeed(!StringUtils.isEmpty(use), "use={0}", use)
                .addFilterIfNeed(!StringUtils.isEmpty(zhuce), "zhuce={0}", zhuce)
                .addFilterIfNeed(null!=status, "status={0}", status)
                .addFilterIfNeed(!StringUtils.isEmpty(education), "education={0}", education)
                .addFilterIfNeed(null!=com, "com={0}", com)
                .addFilterIfNeed(!StringUtils.isEmpty(province), "province={0}", province)
                .addFilterIfNeed(!StringUtils.isEmpty(city), "city={0}", city)
                .addFilterIfNeed(!StringUtils.isEmpty(certificateProvince), "certificate_province={0}", certificateProvince)
                .addFilterIfNeed(!StringUtils.isEmpty(certificateCity), "certificate_city={0}", certificateCity)
                .addFilterIfNeed(!StringUtils.isEmpty(job2), "job2={0}", job2)
                .addFilterIfNeed(!StringUtils.isEmpty(job), "job={0}", job)
                .addFilter("is_del={0}", 1)
                .orderBy("upd_time", false)
        		);
        return new PageUtils(page);
    }
    
    @Override
    public PageUtils queryPage3(Map<String, Object> params) {
    	DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        
        Date startDate=null;
        if(null!=params.get("startDate")&&!StringUtils.isEmpty(params.get("startDate").toString())) {
        	try {
        		startDate=format.parse(params.get("startDate").toString());
			} catch (ParseException e) {
				e.printStackTrace();
			} 
        }
    	Date endDate=null;
        if(null!=params.get("endDate")&&!StringUtils.isEmpty(params.get("endDate").toString())) {
        	try {
        		endDate=format.parse(params.get("endDate").toString());
			} catch (ParseException e) {
				e.printStackTrace();
			} 
        }
    	Integer userId=null;
    	if(null!=params.get("userId")&&!StringUtils.isEmpty(params.get("userId").toString())) {
    		userId=Integer.valueOf(params.get("userId").toString());
    	}
    	
		String name = (String)params.get("name");
		String phone = (String)params.get("phone");
		String jobExperience = (String)params.get("jobExperience");
		
		String contractNum = (String)params.get("contractNum");

		String use = (String)params.get("use");

		String zhuce = (String)params.get("zhuce");

		Integer status=null;
    	if(null!=params.get("status")&&!StringUtils.isEmpty(params.get("status").toString())) {
    		status=Integer.valueOf(params.get("status").toString());
    	}
    	
		Integer com=null;
    	if(null!=params.get("com")&&!StringUtils.isEmpty(params.get("com").toString())) {
    		status=Integer.valueOf(params.get("com").toString());
    	}

		String education = (String)params.get("education");

		
		String province = (String)params.get("province");
		String city = (String)params.get("city");

		String certificateProvince = (String)params.get("certificateProvince");
		String certificateCity = (String)params.get("certificateCity");

		String job2 = (String)params.get("job2");
		String job = (String)params.get("job");

		
        Page<TalentsEntity> page = this.selectPage(
                new Query<TalentsEntity>(params).getPage(),
                new EntityWrapper<TalentsEntity>()
                .ge(null!=startDate, "certificate_date", startDate)
                .le(null!=endDate, "certificate_date", endDate)
                .like(!StringUtils.isEmpty(name), "name", name)
                .addFilterIfNeed(!StringUtils.isEmpty(phone), "phone={0}", phone)
                .addFilterIfNeed(!StringUtils.isEmpty(jobExperience), "job_experience={0}", jobExperience)
                .addFilterIfNeed(!StringUtils.isEmpty(contractNum), "contract_num={0}", contractNum)
                .addFilterIfNeed(!StringUtils.isEmpty(use), "use={0}", use)
                .addFilterIfNeed(!StringUtils.isEmpty(zhuce), "zhuce={0}", zhuce)
                .addFilterIfNeed(null!=status, "status={0}", status)
                .addFilterIfNeed(!StringUtils.isEmpty(education), "education={0}", education)
                .addFilterIfNeed(null!=com, "com={0}", com)
                .addFilterIfNeed(!StringUtils.isEmpty(province), "province={0}", province)
                .addFilterIfNeed(!StringUtils.isEmpty(city), "city={0}", city)
                .addFilterIfNeed(!StringUtils.isEmpty(certificateProvince), "certificate_province={0}", certificateProvince)
                .addFilterIfNeed(!StringUtils.isEmpty(certificateCity), "certificate_city={0}", certificateCity)
                .addFilterIfNeed(!StringUtils.isEmpty(job2), "job2={0}", job2)
                .addFilterIfNeed(!StringUtils.isEmpty(job), "job={0}", job)
                .addFilter("is_del={0}", 0)
                .addFilterIfNeed(null!=userId, "collection={0}", userId)
                .addFilter("collection_status={0}", 1)
                .orderBy("upd_time", false)
        		);
        return new PageUtils(page);
    }
    
    
    @Override
    public PageUtils queryPage4(Map<String, Object> params) {
    	DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");        
        Date startDate=null;
        if(null!=params.get("startDate")&&!StringUtils.isEmpty(params.get("startDate").toString())) {
        	try {
        		startDate=format.parse(params.get("startDate").toString());
			} catch (ParseException e) {
				e.printStackTrace();
			} 
        }
    	Date endDate=null;
        if(null!=params.get("endDate")&&!StringUtils.isEmpty(params.get("endDate").toString())) {
        	try {
        		endDate=format.parse(params.get("endDate").toString());
			} catch (ParseException e) {
				e.printStackTrace();
			} 
        }
    	Integer userId=null;
    	if(null!=params.get("userId")&&!StringUtils.isEmpty(params.get("userId").toString())) {
    		userId=Integer.valueOf(params.get("userId").toString());
    	}
    	
		String name = (String)params.get("name");
		String phone = (String)params.get("phone");
		String jobExperience = (String)params.get("jobExperience");
		
		String contractNum = (String)params.get("contractNum");

		String use = (String)params.get("use");

		String zhuce = (String)params.get("zhuce");

		Integer status=null;
    	if(null!=params.get("status")&&!StringUtils.isEmpty(params.get("status").toString())) {
    		status=Integer.valueOf(params.get("status").toString());
    	}
    	
		Integer com=null;
    	if(null!=params.get("com")&&!StringUtils.isEmpty(params.get("com").toString())) {
    		status=Integer.valueOf(params.get("com").toString());
    	}

		String education = (String)params.get("education");

		
		String province = (String)params.get("province");
		String city = (String)params.get("city");

		String certificateProvince = (String)params.get("certificateProvince");
		String certificateCity = (String)params.get("certificateCity");

		String job2 = (String)params.get("job2");
		String job = (String)params.get("job");

		
        Page<TalentsEntity> page = this.selectPage(
                new Query<TalentsEntity>(params).getPage(),
                new EntityWrapper<TalentsEntity>()
                .addFilterIfNeed(null!=userId, "user_id={0}", userId)
                .ge(null!=startDate, "certificate_date", startDate)
                .le(null!=endDate, "certificate_date", endDate)
                .like(!StringUtils.isEmpty(name), "name", name)
                .addFilterIfNeed(!StringUtils.isEmpty(phone), "phone={0}", phone)
                .addFilterIfNeed(!StringUtils.isEmpty(jobExperience), "job_experience={0}", jobExperience)
                .addFilterIfNeed(!StringUtils.isEmpty(contractNum), "contract_num={0}", contractNum)
                .addFilterIfNeed(!StringUtils.isEmpty(use), "use={0}", use)
                .addFilterIfNeed(!StringUtils.isEmpty(zhuce), "zhuce={0}", zhuce)
                .addFilterIfNeed(null!=status, "status={0}", status)
                .addFilterIfNeed(!StringUtils.isEmpty(education), "education={0}", education)
                .addFilterIfNeed(null!=com, "com={0}", com)
                .addFilterIfNeed(!StringUtils.isEmpty(province), "province={0}", province)
                .addFilterIfNeed(!StringUtils.isEmpty(city), "city={0}", city)
                .addFilterIfNeed(!StringUtils.isEmpty(certificateProvince), "certificate_province={0}", certificateProvince)
                .addFilterIfNeed(!StringUtils.isEmpty(certificateCity), "certificate_city={0}", certificateCity)
                .addFilterIfNeed(!StringUtils.isEmpty(job2), "job2={0}", job2)
                .addFilterIfNeed(!StringUtils.isEmpty(job), "job={0}", job)
                .addFilter("is_del={0}", 0)
                .isNotNull("collection")
                .orderBy("upd_time", false)
        		);
        return new PageUtils(page);
    }

}
